﻿using Microsoft.AspNetCore.Mvc;
using S2_Xxxx_XxxNetApi.Services;
using S2Cloud.SmartFlow.GrpcHelper;
using S2Cloud.SmartFlow.GrpcHelper.Entity;
using System;
using System.Data;

namespace S2_Xxxx_XxxNetApi.Controllers
{
    [Route("Xxxapi/[controller]/[action]")]
    public class UserController : ControllerBase
    {
        [HttpGet]
        public dynamic TestSession(string UserId)
        {

            SessionHelper.SetString(this, "UserId", UserId);
            return new { userId = UserId, Msg = "调用成功" };
        }

        [HttpGet]
        public dynamic GetSession(string Key)
        {
            return SessionHelper.GetString(this, Key);
        }

        [HttpGet]
        public dynamic TestCookie(string UserId)
        {

            CookieHelper.SetCookie(this, "UserId", UserId, 5);
            return new { userId = UserId, Msg = "调用成功" };
        }

        [HttpGet]
        public dynamic GetCookie(string Key)
        {
            return CookieHelper.GetCookie(this, Key);
        }

        [HttpGet]
        public dynamic testCustomSetting(string key)
        {
            try
            {
                Result<string> result = GrpcClientSingle.S2GrpcClient.customSettingManager.GetCustomSetting(key);
                return new { userId = "zengxie", Msg = "调用成功", Code = 200 };
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);

                return ex.Message;
            }
        }

        [HttpGet]
        public dynamic GetUserList()
        {
            UserServices service = new UserServices();
            DataTable dt = service.GetData();
            return dt;
            #region 条件测试
            //List<t_user> list = service.GetUserList();
            //return list;
            #endregion

            #region Insert(T model) 测试
            //return BaseRepository<t_user>.Insert(new t_user
            // {
            //     ObjectID = Guid.NewGuid().ToString(),
            //     Name="张鑫",
            //     Code="2021001",
            //     Email="953698506@qq.com",
            //     BankAccount="2321111111134444"

            // }, true) ;
            #endregion

            #region Insert(List<T> listModel) 测试
            //List<t_user> listParam = new List<t_user>() {
            //    new t_user(){Name = "张三",Code="10001",ObjectID=Guid.NewGuid().ToString()},
            //    new t_user(){Name = "李四",Code="10002",ObjectID=Guid.NewGuid().ToString()},
            //    new t_user(){Name = "王五",Code="10003",ObjectID=Guid.NewGuid().ToString()},
            //    new t_user(){Name = "赵六",Code="10004",ObjectID=Guid.NewGuid().ToString()},
            //    new t_user(){Name = "甲",Code="10005",ObjectID=Guid.NewGuid().ToString()},
            //    new t_user(){Name = "乙",Code="10006",ObjectID=Guid.NewGuid().ToString()},
            //};
            //return BaseRepository<t_user>.Insert(listParam);
            #endregion

            #region 翻页测试



            //BaseRepository.GetBysql("")

            //int pageCount = 0;
            // List<t_user> list = BaseRepository<t_user>.GetByPage(null, "code", "asc", 10, 4, out pageCount);
            //return list;
            #endregion

            #region Edit(T model) 测试

            //return BaseRepository<t_user>.Edit(new t_user
            //{
            //    ObjectID= "7b3358dd-8353-4ff6-b72e-b05ad4260983",
            //    Code = "1000999"
            //}, false);
            #endregion

            #region Edit(List<T> listModel) 测试
            //int index = 1;
            //foreach (t_user m in list)
            //{
            //    m.Name = "批量修改" + index;
            //    index++;
            //}
            //return BaseRepository<t_user>.Edit(list);
            #endregion

            #region Delete(T model) 测试
            //return BaseRepository<t_user>.Delete(list[0]);
            #endregion

            #region Delete(List<T> listModel) 测试
            // return BaseRepository<t_user>.Delete(list);
            #endregion
        }
        [HttpGet]
        public dynamic GetUserPageList(int pageSize, int pageNumber)
        {
            int pageCount = 0;
            UserServices service = new UserServices();
            DataTable dt = service.GetPageData(pageSize, pageNumber, out pageCount);
            return new { pageCount = pageCount,pageData = dt };
        }
    }
}